/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.integral.web.controller.manager;


import cn.hutool.core.bean.BeanUtil;
import com.medusa.gruul.common.core.exception.ServiceException;
import com.medusa.gruul.common.core.util.Result;
import com.medusa.gruul.common.core.util.SystemCode;
import com.medusa.gruul.common.data.tenant.ShopContextHolder;
import com.medusa.gruul.integral.service.IIntegralShopService;
import com.medusa.gruul.integral.web.model.dto.manager.IntegralShopDto;
import com.medusa.gruul.integral.web.model.vo.IntegralShopVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 积分商城表 前端控制器
 * </p>
 *
 * @author xiaoq
 * @since 2019-11-19
 */
@RestController
@RequestMapping("/manager/shop")
@Api(tags = "积分商城接口")
public class IntegralShopController {
    @Autowired
    private IIntegralShopService integralShopService;


    /**
     * 修改店铺状态(关闭或开启积分商城)
     *
     * @param status 状态值
     * @return
     */
    @GetMapping("update/status")
    @ApiOperation(value = "积分商城开启关闭")
    public Result updateIntegralShopStatus(@ApiParam(value = "状态值", required = true) Boolean status) {
        String shopId = ShopContextHolder.getShopId();
        integralShopService.updateIntegralShopStatus(shopId, status);
        return Result.ok();
    }


    /**
     * 查看店铺信息 (店铺状态)
     *
     * @return 店铺信息
     */
    @GetMapping("get/shopId")
    @ApiOperation(value = "商城信息")
    public Result<IntegralShopVo> getIntegralShopInfo() {
        String shopId = ShopContextHolder.getShopId();
        IntegralShopVo integralShopInfo = integralShopService.getIntegralShopInfo(shopId);
        if (BeanUtil.isEmpty(integralShopInfo)) {
            throw new ServiceException("商城信息不存在 !", SystemCode.DATA_NOT_EXIST.getCode());
        }
        return Result.ok(integralShopInfo);
    }


    /**
     * 默认新增商铺默认值
     *
     * @param integralShopDto
     * @return
     */
    @PostMapping("add")
    @ApiOperation(value = "新增商城默认值 --未对接")
    public Result saveShopInfo(@RequestBody IntegralShopDto integralShopDto) {
        integralShopService.addShopInfo(integralShopDto);
        return Result.ok();
    }


}
